package com.itheima.converter;

import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

public class DateConverter implements Converter<String, Date> {

    public Date convert(String source) {
        System.out.println("来到我们的转化器里面了：" + source);
        String newSource=source;

        try {
            //1. 定义SimpleDateFormat对象
            SimpleDateFormat df = null;
            if (source.contains("-")) {
                df = new SimpleDateFormat("yyyy-MM-dd");
            } else if (source.contains("/")) {
                df = new SimpleDateFormat("yyyy/MM/dd");
            }

            return df.parse(source);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return null;
    }
}
